# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=mesa

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=10.0.2
pkgrel=1
pkgdesc="Open-source implementation of the OpenGL specification (mingw-w64)"
arch=('any')
depends=("")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-clang" "scons" "libxml2-python" "python2")
#groups=("${MINGW_PACKAGE_PREFIX}")
url="http://www.mesa3d.org"
license=('MIT')
options=('staticlibs' 'strip')
source=(ftp://ftp.freedesktop.org/pub/mesa/${pkgver}/MesaLib-${pkgver}.tar.bz2)
md5sums=('8544c0ab3e438a08b5103421ea15b6d2')
noextract=("MesaLib-${pkgver}.tar.bz2")

case ${MINGW_CHOST} in
  i686*)
    _mach=x86
  ;;
  x86_64*)
    _mach=x86_64
  ;;
esac
  
prepare() {
  cd ${startdir}
  [ -d $srcdir/$_realname-$pkgver ] || tar -xjvf MesaLib-${pkgver}.tar.bz2 -C $srcdir
}

build() {
  cd ${srcdir}/Mesa-$pkgver

  LLVM=${MINGW_PREFIX} LDFLAGS="-static -s" scons build=release platform=windows toolchain=mingw machine=${_mach} libgl-gdi #mesagdi
}

package() {
  cd ${srcdir}/Mesa-$pkgver

  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  #mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/mesa
  local _dll_files=( $(find ${srcdir}/Mesa-$pkgver -type f -name "*.dll") )
  cp -f ${_dll_files[@]} ${pkgdir}${MINGW_PREFIX}/bin/
  #local _dlla_files=( $(find ${srcdir}/Mesa-$pkgver -type f -name "*.a") )
  #cp -f ${_dlla_files[@]} ${pkgdir}${MINGW_PREFIX}/lib/mesa/
}
